package com.moyu.common.elasticsearch.config;

import com.moyu.common.core.constants.RabbitMQConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * ES Topic配置类
 *
 * @Author 赵彦博
 * @Date 2024/12/21 9:51
 */
@Configuration
public class TopicElasticSearchConfig {
    @Bean
    public TopicExchange saveExchange() {
        return new TopicExchange(RabbitMQConstants.ES_SAVE_EXCHANGE, true, false);
    }

    @Bean
    public TopicExchange deleteExchange() {
        return new TopicExchange(RabbitMQConstants.ES_DELETE_EXCHANGE, true, false);
    }

    @Bean
    public Queue esSaveQueue() {
        return new Queue(RabbitMQConstants.ES_SAVE_QUEUE, true);
    }

    @Bean
    public Queue esDeleteQueue() {
        return new Queue(RabbitMQConstants.ES_DELETE_QUEUE, true);
    }

    @Bean
    public Binding esSaveBinding() {
        return BindingBuilder.bind(esSaveQueue()).to(saveExchange()).with(RabbitMQConstants.ES_KEY);
    }

    @Bean
    public Binding esDeleteBinding() {
        return BindingBuilder.bind(esDeleteQueue()).to(deleteExchange()).with(RabbitMQConstants.ES_KEY);
    }

}
